package cn.tpshion.devops.controller;

import cn.tpshion.devops.common.Result;
import cn.tpshion.devops.domain.dto.FlowTemplateDTO;
import cn.tpshion.devops.domain.dto.HistoryLogDTO;
import cn.tpshion.devops.domain.dto.TaskWorkDTO;
import cn.tpshion.devops.domain.entity.FlowHistory;
import cn.tpshion.devops.domain.entity.FlowTemplate;
import cn.tpshion.devops.domain.entity.TaskWork;
import cn.tpshion.devops.service.FlowService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/flow")
public class FlowController {

    @Resource
    private FlowService flowService;

    @PostMapping("/saveTemplate")
    public Result saveTemplate(@Valid @RequestBody FlowTemplate flowTemplate){
        flowService.saveTemplate(flowTemplate);
        return Result.ok();
    }

    @PostMapping("/getTemplate")
    public Result<TaskWork> getTemplate(@Valid @RequestBody FlowTemplateDTO dto){
        return Result.ok(flowService.getTemplate(dto));
    }

    @PostMapping("/templateList")
    public Result<Set<String>> templateList(){
        return Result.ok(flowService.templateList());
    }

    @PostMapping("deleteTemplate")
    public Result deleteTemplate(@Valid @RequestBody FlowTemplateDTO dto){
        flowService.deleteTemplate(dto);
        return Result.ok();
    }

    @PostMapping("/historyList")
    public Result<List<FlowHistory>> historyList(@Valid @RequestBody TaskWorkDTO dto){
        return Result.ok(flowService.historyList(dto));
    }

    @PostMapping("/historyLog")
    public Result<List<String>> historyLog(@Valid @RequestBody HistoryLogDTO dto){
        return Result.ok(flowService.historyLog(dto));
    }
}
